package com.jadesoft.listener;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.io.Writer;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;

public class PostMethodExample {

	public static void main(String args[]) throws Exception {
		HttpClient client = new HttpClient();
		client.getHostConfiguration().setProxy("11.133.190.13", 8080);
		File file = new File("c:\\stock.txt");
		Writer writer = new FileWriter(file);
		file.deleteOnExit();
		file.createNewFile();
		for (int i = 0; i < 40; i++) {
			String uri = "http://hqdigi2.eastmoney.com/EM_Quote2010NumericApplication/index.aspx?"
					+ "type=s&sortType=C&sortRule=-1&pageSize=20000&page=1&jsName=quote_123&style=";
			BufferedReader br = null;
			System.out.println(i);
			uri += i;
			GetMethod method = new GetMethod(uri);
			HttpMethodParams params = new HttpMethodParams();

			writer.append(i + " ");
			try {
				int returnCode = client.executeMethod(method);
				if (returnCode == HttpStatus.SC_NOT_IMPLEMENTED) {
					System.err
							.println("The get method is not implemented by this URI");
					method.getResponseBodyAsString();
				} else {
					br = new BufferedReader(new InputStreamReader(method
							.getResponseBodyAsStream(), "utf-8"));
					String readLine;
					while (((readLine = br.readLine()) != null)) {
						 System.out.println("size: " + (readLine.indexOf("]")-readLine.indexOf("[")));
//						writer.append(readLine+"\n");
					}
				}
			} catch (Exception e) {
				System.err.println(e);
			} finally {
				method.releaseConnection();
				if (br != null)
					try {
						br.close();
					} catch (Exception fe) {
					}
			}

		}
	}
}